import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { HTTP_BASE_URL, SERVERS_NAME } from '../../../config/config';
import {StatusEnum} from '../../../core/enum/status.enum';
import {NzMessageService} from 'ng-zorro-antd';
import {SystemFormService} from './system-form.service';

@Component({
  selector: 'app-system-form',
  templateUrl: './system-form.component.html',
  styleUrls: ['./system-form.component.scss'],
  providers: [SystemFormService]
})
export class SystemFormComponent implements OnInit {
  @Input() currObj: any;
  @Input() opreatType: number; // 1,制度收文进入,2,执行反馈进入,3.制度归档进入
  @Output() backemit = new EventEmitter();

  imgPixe = `${HTTP_BASE_URL}${SERVERS_NAME.SECURITY_SERVER}source/view/`;
  materialObj = null;
  remark = null;
  pageName = null;

  stateObj = {
    0: '新增',
    5: '修改',
    10: '停用'
  };

  constructor(
    private service: SystemFormService,
    private message: NzMessageService,
  ) { }

  ngOnInit() {
    if (this.opreatType == 1 || this.opreatType == 2) {
      this.pageName = '查看';
    } else if (this.opreatType == 3) {
      this.pageName = '预览';
    }
    this.getDetails();
  }

  // tabs数据查询
  getDetails() {
    let opt = null;
    let obj = null;
    if (this.opreatType == 1 || this.opreatType == 3) {
      opt = 'view';
      obj = this.currObj.id;
    } else if (this.opreatType == 2) {
      opt = 'viewInstitution';
      obj = {
        id: this.currObj.id
      };
    }
    this.service[opt](obj).subscribe(res => {
      if (res.status === StatusEnum.SUCCESS) {
        this.materialObj = res.datas;
        if (this.materialObj.sourceList && this.materialObj.sourceList.length > 0) {
          this.materialObj.source = this.imgPixe + this.materialObj.sourceList[0].moduleName + '/' + this.materialObj.sourceList[0].fileNewName;
        }
      }
    });
  }

  /**
   * pdf页面载入时,跳转到最新的那一页
   */
  pdfLoad(e) {
  }

  back(flag) {
    this.backemit.emit(flag);
  }

}

